Skip to content

block: enable RWF_DONTCACHE for block devices - #1040

Closed
blktests-ci-kpd[bot] wants to merge 6 commits into
linus-master_basefrom
series/1137152=>linus-master
Closed

blktests-ci-kpd[bot] wants to merge 6 commits into
linus-master_basefrom
series/1137152=>linus-master

Conversation

@blktests-ci-kpd

Copy link
Copy Markdown

Pull request for series with
subject: block: enable RWF_DONTCACHE for block devices
version: 7
url: https://patchwork.kernel.org/project/linux-block/list/?series=1137152

@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 2d2338c
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 0d83957
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from b360c95 to a19db5b Compare August 6, 2026 09:22
@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the linus-master_base branch 2 times, most recently from 612ae31 to 863d43a Compare August 9, 2026 07:24
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 06cf618
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from a19db5b to 33e3f2f Compare August 9, 2026 08:50
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: d58772d
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from 33e3f2f to 0904d61 Compare August 10, 2026 23:20
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: f5bbbfe
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from 0904d61 to 1b24d65 Compare August 12, 2026 14:56
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 3d6d817
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from 1b24d65 to 2f9e00b Compare August 12, 2026 20:09
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 3aa1dca
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from 2f9e00b to 985cd5d Compare August 13, 2026 21:05
@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the linus-master_base branch 2 times, most recently from d89ab11 to fdba928 Compare August 16, 2026 18:34
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: fd923b3
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from 985cd5d to ca05e36 Compare August 16, 2026 21:14
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 8d3ae59
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from ca05e36 to 25a5575 Compare August 17, 2026 20:38
Move the atomic context detection logic from erofs's z_erofs_in_atomic()
into the block layer as bio_in_atomic(). This helper returns true when
the current context is unsafe for sleeping bio completion handlers (e.g.,
hard/soft IRQ, preempt-disabled).

The logic was originally added to erofs in commit c99fab6 ("erofs:
fix atomic context detection when !CONFIG_DEBUG_LOCK_ALLOC"). A
subsequent patch will use it in the block layer's bio completion
infrastructure, so move it to include/linux/bio.h where both subsystems
can share it.

Convert erofs to call the new bio_in_atomic() directly.

Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Some bio completion handlers need to run from preemptible task context,
but bio_endio() may be called from IRQ context (e.g., buffer_head
writeback). Callers need a way to ensure their callback eventually runs
from a sleepable context. Add infrastructure for that, in two forms:

  1. BIO_COMPLETE_IN_TASK, a bio flag the submitter sets when it knows
     in advance that its callback needs task context (e.g., dropbehind
     writeback). bio_endio() sees the flag and offloads completion to a
     worker automatically.

  2. bio_complete_in_task(), a helper that completion callbacks can
     invoke from within bi_end_io() when the deferral decision is
     dynamic (e.g., fserror reporting).

Both share a per-CPU list drained by a work item on a WQ_PERCPU
workqueue. Producers push the bio onto the local CPU's list and schedule
the work item, which then dispatches each bio's bi_end_io() from task
context.

Both methods are gated on bio_in_atomic(), which returns true in any
context where a sleeping bi_end_io() is unsafe, including
non-preemptible task context.

Two CPU hotplug callbacks are used to drain remaining bios from the
departing CPU's batch, while maintaining the per-CPU behavior. The
CPUHP_AP_ONLINE_DYN callback disables the per-CPU work item while the
CPU is still online, preventing it from running on an unbound worker
later. CPUHP_BP_PREPARE_DYN then drains any bios added between disabling
the work item and CPU offline.

Link: https://lore.kernel.org/all/20260409160243.1008358-1-hch@lst.de/
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Set BIO_COMPLETE_IN_TASK on iomap writeback bios when a dropbehind folio
is added. This ensures that bi_end_io runs in task context, where
folio_end_dropbehind() can safely invalidate folios.

With the bio layer now handling task-context deferral generically,
IOMAP_IOEND_DONTCACHE is no longer needed, as XFS no longer needs to
route DONTCACHE ioends through its completion workqueue. Remove the flag
and its NOMERGE entry.

Without the NOMERGE, regular I/Os that get merged with a dropbehind
folio will also have their completion deferred to task context.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Set BIO_COMPLETE_IN_TASK in __bh_submit() for write bios when the folio
has dropbehind set, so that buffer_head writeback completions get
deferred to task context where folio_end_dropbehind() can safely
invalidate folios.

Read completions are not deferred since dropbehind invalidation for
reads is handled synchronously by the reader.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
Block device buffered reads and writes already pass through
filemap_read() and iomap_file_buffered_write() respectively, both of
which handle IOCB_DONTCACHE. Enable RWF_DONTCACHE for block device files
by setting FOP_DONTCACHE in def_blk_fops.

For CONFIG_BUFFER_HEAD=y, writeback goes through buffer_head's
__bh_submit() which sets BIO_COMPLETE_IN_TASK on dropbehind folios. For
CONFIG_BUFFER_HEAD=n, writeback goes through iomap which handles it via
BIO_COMPLETE_IN_TASK on the ioend bio.

This support is useful for databases that operate on raw block devices,
among other userspace applications.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: bd5f485
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1137152=>linus-master branch from 25a5575 to 2f42663 Compare August 19, 2026 07:12
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 66498c7
series: https://patchwork.kernel.org/project/linux-block/list/?series=1137152
version: 7

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-block/list/?series=1137152
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: block: introduce bio_in_atomic()
Using index info to reconstruct a base tree...
M	fs/erofs/zdata.c
M	include/linux/bio.h
Falling back to patching base and 3-way merge...
Auto-merging include/linux/bio.h
CONFLICT (content): Merge conflict in include/linux/bio.h
Auto-merging fs/erofs/zdata.c
Patch failed at 0001 block: introduce bio_in_atomic()
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc include/linux/bio.h
index bb3235497e67,62a983758e09..000000000000
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@@ -383,30 -383,6 +383,33 @@@ static inline bool bio_in_atomic(void
  	return !preemptible();
  }
  
++<<<<<<< HEAD
 +void __bio_complete_in_task(struct bio *bio);
 +
 +/**
 + * bio_complete_in_task - ensure a bio is completed in preemptible task context
 + * @bio: bio to complete
 + *
 + * If called from non-task context, offload the bio completion to a worker
 + * thread and return %true. Else return %false and do nothing.
 + *
 + * Uses BIO_COMPLETE_IN_TASK as a sentinel: if set, the bio was already
 + * deferred and we are running in the worker — return %false so the
 + * callback proceeds instead of re-deferring.
 + */
 +static inline bool bio_complete_in_task(struct bio *bio)
 +{
 +	if (bio_flagged(bio, BIO_COMPLETE_IN_TASK))
 +		return false;
 +	if (!bio_in_atomic())
 +		return false;
 +	bio_set_flag(bio, BIO_COMPLETE_IN_TASK);
 +	__bio_complete_in_task(bio);
 +	return true;
 +}
 +
++=======
++>>>>>>> block: introduce bio_in_atomic()
  extern void bio_endio(struct bio *);
  
  /**

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the linus-master_base branch 2 times, most recently from 055a766 to 341ae8c Compare August 29, 2026 06:35
@blktests-ci-kpd

Copy link
Copy Markdown
Author

At least one diff in series https://patchwork.kernel.org/project/linux-block/list/?series=1137152 irrelevant now for [{'archived': False, 'project': 241}] search patterns

@blktests-ci-kpd blktests-ci-kpd Bot closed this Aug 29, 2026
@blktests-ci-kpd
blktests-ci-kpd Bot deleted the series/1137152=>linus-master branch August 31, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant